<?php
	//******************************
	//   Create our WordPress widgets
	//******************************
	
	class sh_links_widget extends WP_Widget {
		function sh_links_widget() {
			//widget settings
			$widget_ops = array(
				'classname' => 'Social Hub Links',
				'description' => 'Displays a list of links setup in the settings page for the Social Hub plugin.'
			);
			
			//widget control settings
			$control_ops = array(
				'width' => 250,
				'height' => 350,
				'id_base' => 'sh_links_widget'
			);
			
			//create the widget
			$this->WP_Widget('sh_links_widget', 'Social Hub Links', $widget_ops, $control_ops);
		}
		
		function form($instance) {
			$title = esc_attr($instance['title']); ?>
			
			<div>
				<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?></label>
				<input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" class="widefat" value="<?php echo $title; ?>" />
				<span class="description">Widget works best in the sidebar.</span>
			</div>
		<?php }
		
		function update($new_instance, $old_instance) {
			$instance = $old_instance;
			$instance['title'] = strip_tags($new_instance['title']);
			
			return $instance;
		}
		
		function widget($args, $instance) {
			extract($args); 
			$title = apply_filters('widget_title', $instance['title']); ?>
			
			<h3 class="widget-title"><?php echo $title; ?></h3>
			<?php sh_links();
			
		}
	}
	
	function sh_load_links_widget() {
		register_widget('sh_links_widget');
	}
	add_action('widgets_init', 'sh_load_links_widget');
	
	
	
	
	
	class sh_facebook_widget extends WP_Widget {
		function sh_facebook_widget() {
			//widget settings
			$widget_ops = array(
				'classname' => 'Social Hub Facebook Widget',
				'description' => 'Displays the Facebook Like Box Widget setup in the settings page for the Social Hub plugin.'
			);
			
			//widget control settings
			$control_ops = array(
				'width' => 292,
				'height' => 350,
				'id_base' => 'sh_facebook_widget'
			);
			
			//create the widget
			$this->WP_Widget('sh_facebook_widget', 'Social Hub Facebook Widget', $widget_ops, $control_ops);
		}
		
		function form($instance) {
			$title = esc_attr($instance['title']); ?>
			
			<div>
				<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?></label>
				<input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" class="widefat" value="<?php echo $title; ?>" />
				<input type="checkbox" id="enable" <?php if($enable == true) { echo 'checked="checked"'; } ?> value="true" />
				<label for="enable"><?php _e('Use title in widget'); ?></label><br />
				<span class="description">Widget works best in the sidebar</span>
			</div>
		<?php }
		
		function update($new_instance, $old_instance) {
			$instance = $old_instance;
			$instance['title'] = strip_tags($new_instance['title']);
			
			return $instance;
		}
		
		function widget($args, $instance) {
			extract($args);
			$title = apply_filters('widget_title', $instance['title']); ?>
			
			<h3 class="widget-title"><?php echo $title; ?></h3>
			<?php sh_facebook_widget();
		}
	}
	
	function sh_load_facebook_widget() {
		register_widget('sh_facebook_widget');
	}
	add_action('widgets_init', 'sh_load_facebook_widget');
	
	
	
	
	
	class sh_twitter_widget extends WP_Widget {
		function sh_twitter_widget() {
			//widget settings
			$widget_ops = array(
				'classname' => 'Social Hub Twitter Widget',
				'description' => 'Displays a feed of your latest Tweets'
			);
			
			//widget control settings
			$control_ops = array(
				'width' => 292,
				'height' => 350,
				'id_base' => 'sh_twitter_widget'
			);
			
			$this->WP_Widget('sh_twitter_widget', 'Social Hub Twitter Widget', $widget_ops, $control_ops);
		}
		
		function form($instance) {
			$title = esc_attr($instance['title']); ?>
			
			<div>
				<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title'); ?></label>
				<input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" class="widefat" value="<?php echo $title; ?>" />
				<span class="description">Widget works best in the sidebar</span>
			</div>
		<?php }
		
		function update($new_instance, $old_instance) {
			$instance = $old_instance;
			$instance['title'] = strip_tags($new_instance['title']);
			
			return $instance;
		}
		
		function widget($args, $instance) {
			extract($args);
			$title = apply_filters('widget_title', $instance['title']); ?>
			
			<h3 class="widget-title"><?php echo $title; ?></h3>
			<?php sh_twitter_widget();
		}
	}
	
	function sh_load_twitter_widget() {
		register_widget('sh_twitter_widget');
	}
	add_action('widgets_init', 'sh_load_twitter_widget');

?>